using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using THANHTUNGO.Portal.Components.UI;

namespace MONA.Modules.Marketing.Controls
{
    public class ItemControl : YAFPage
    {
        private int _ItemID = 0;
        private bool _ShowUpdateBar = true;
        private bool _IsPopup = false;

        [Browsable(true)]
        [CategoryAttribute("Appearance"), DefaultValueAttribute(0)]
        public int ItemID
        {
            get
            {
                if (this._IsPopup == false)
                {
                    if (HttpContext.Current != null && Request.Params["ItemID"] != null)
                        return Int32.Parse(Request.Params["ItemID"]);
                }
                return this._ItemID;
            }
            set { this._ItemID = value; }
        }

        [Browsable(true)]
        [CategoryAttribute("Appearance"), DefaultValueAttribute("true")]
        public bool ShowUpdateBar
        {
            get { return this._ShowUpdateBar; }
            set { this._ShowUpdateBar = value; }
        }

        [Browsable(true)]
        [CategoryAttribute("Appearance"), DefaultValueAttribute("false")]
        public bool IsPopup
        {
            get { return this._IsPopup; }
            set { this._IsPopup = value; }
        }

        protected void ReturnToReferrerPage()
        {
            if (this.IsPopup == false)
            {
                // Redirect back.
                if (Request.QueryString["ReturnUrl"] != null)
                {
                    int pos = Request.RawUrl.IndexOf("returnUrl");
                    string returnUrl = Request.RawUrl.Substring(pos + 10);
                    Response.Redirect(Server.UrlDecode(returnUrl));
                }
            }
        }
    }
}